﻿using System;
using System.Linq;
using System.Linq.Expressions;
using System.Web;

namespace WebApplication1 {
	public class IISHandler1 : IHttpHandler {
		/// <summary>
		/// You will need to configure this handler in the web.config file of your 
		/// web and register it with IIS before being able to use it. For more information
		/// see the following link: http://go.microsoft.com/?linkid=8101007
		/// </summary>
		#region IHttpHandler Members

		public bool IsReusable {
			// Return false in case your Managed Handler cannot be reused for another request.
			// Usually this would be false in case you have some state information preserved per request.
			get { return true; }
		}

		public void ProcessRequest(HttpContext context) {
			if (context.Request.Params.AllKeys.Contains("a") && context.Request.Params.AllKeys.Contains("b")) {
				R1(context);
			} else if (context.Request.Params.AllKeys.Contains("c")) {
				R2(context);
			}
		}

		private void R2(HttpContext context) {
			context.Response.Write(string.Format("{{\"id\":\"{0}\",\"question\":\"{1}\",\"author\":\"{2}\",\"arr\":[{3}]}}", "12", "Life is cool", "DK1988", "2, 4, 5, 6, 7, 0"));
		}

		private void R1(HttpContext context) {
			System.Threading.Thread.Sleep(Convert.ToInt32(context.Request.Params["a"]));
			context.Response.Write(context.Request.Params["a"] + context.Request.Params["b"] + "qqqqqqqq");
		}

		#endregion
	}
}
